package com.liuzhilong.infrastructure.basic.jdk.thread;

import java.util.concurrent.*;

public class ThreadUse {

   public static    ExecutorService RECEIVER_POOL;//队列满了的处理策略
    static {
        RECEIVER_POOL = new ThreadPoolExecutor(5, //常驻5个线程
                100,//最大扩展到100个线程
                0,//非核心线程的空闲时间
                TimeUnit.SECONDS,//
                new ArrayBlockingQueue<Runnable>(512), // 使用有界队列，避免OOM
                new ThreadPoolExecutor.AbortPolicy());
        System.out.println("开启线程池");
        Runtime.getRuntime().addShutdownHook(new Thread(){
            @Override
            public void run() {
                RECEIVER_POOL.shutdown();
                System.out.println("关闭线程池");
            }
        });


    }
    public static void main(String[] args) {
        Future result =  RECEIVER_POOL.submit(() -> {
           Thread.currentThread().wait(1000);
            return "";
        });

        RECEIVER_POOL.shutdown();
    }



}
